﻿using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Yichat.MicroService.Interface;

namespace Yichat.MicroService.ConfigCenterService.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class ConfigsController : Controller
    {
        private readonly IConfigOptionService _configOptionService;
        public ConfigsController(IConfigOptionService configOptionService)
        {
            _configOptionService = configOptionService;
        }

        [HttpGet]
        public async Task<IEnumerable<KeyValuePair<string, string>>> Get()
        {
            //var configs = new List<KeyValuePair<string, string>>();
            //configs.Add(new KeyValuePair<string, string>("SecretKey", "1238918290381923"));
            //configs.Add(new KeyValuePair<string, string>("ConnectionString", "user=123;password=123;server=."));

            var configs = await _configOptionService.GetConfigOptionsAsync();
            return configs.Select(a => new KeyValuePair<string, string>(a.Key, a.Value));
        }
    }
}
